import {getCategoryApi} from "@/apis/category.js";
import {ref,onMounted} from "vue";
import {onBeforeRouteUpdate, useRoute} from "vue-router";


export function userCategory(){
    // 获取category
    const route = useRoute();
    const  categoryData = ref({})
    const getCategory = async (id = route.params.id) =>{
        const res = await getCategoryApi(id)
        categoryData.value = res.result
    }
    onMounted(() =>{
        getCategory()
    })
// onUpdated(() => getCategory())
    onBeforeRouteUpdate((to)=>getCategory(to.params.id))
    return{
        categoryData
    }
}